package com.aiti.lulian.controller.newCard;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.aiti.base.core.exception.BusinessException;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.service.newCard.TestService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * description:
 * auth fcb
 * date 2025-10-10 19:47
 **/
@RestController
@RequestMapping("/new-card")
@Slf4j
@Api(tags = "迁移旧数据接口")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/enterpriseAddAdminCard")
    public Message enterpriseAddAdminCard(@RequestParam("enterpriseId") String enterpriseId,
                                          @RequestParam(value = "enterpriseAdminUsername",required = false)String enterpriseAdminUsername,
                                          @RequestParam("zhengFu")Integer zhengFu) {
        try {
            testService.createEnterpriseAdminCard(enterpriseId, enterpriseAdminUsername, zhengFu);
            return Message.success();
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("添加企业管理员异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("添加企业管理员异常");
        }
    }

    @GetMapping("/enterpriseAddUserCard")
    public Message enterpriseAddUserCard(@RequestParam("enterpriseId") String enterpriseId) {
        try {
            testService.createEnterpriseUserCard(enterpriseId);
            return Message.success();
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("添加企业用户异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("添加企业用户异常：" + e.getMessage());
        }
    }

    @PostMapping("/addCardAddress")
    public Message addCardAddress(@RequestBody List<String> enterpriseIdList) {
        try {
            testService.addCardAddress(enterpriseIdList);
            return Message.success();
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("添加地址异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("添加地址异常：" + e.getMessage());
        }
    }
}
